package basicJava.generics.generics3;

import java.util.ArrayList;
import java.util.Collection;

import javax.swing.Box.Filler;

import basicJava.generics.generics2.Coffee;
import basicJava.generics.generics2.CoffeeGenerator;
import basicJava.generics.generics2.Generator;

public class Generators {
	
	//用于Generator的泛型方法
	public static <T> Collection<T> fill(Collection<T> coll,Generator<T> gen,int n){
		for (int i = 0; i < n; i++) {
			coll.add(gen.next());
		}
		return coll;
	}
	
	public static void main(String[] args){
		//fill()方法可以透明的应用于Coffee和Integer的容器和生成器
		Collection<Coffee> coffee = fill(new ArrayList<Coffee>(), new CoffeeGenerator(), 4);
		for (Coffee c:coffee) {
			System.out.println(c);
		}
	
	}
}
